package com.org.web.handle.user.controller;

import com.org.platform.entity.vo.UserVo;
import com.org.platform.model.ResultModel;
import com.org.web.handle.user.service.UserService;
import com.org.web.support.base.BaseController;
import javax.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

/**
 * @author devg
 * @Date 2020/2/26 10:50
 */
@RestController
@RequestMapping(value = {"/user"})
public class UserController extends BaseController {

  @Autowired
  private UserService userService;

  @RequestMapping(value = {"/login"})
  public ModelAndView index() {
    return modelAndView("/front/login");
  }

  /**
   * 登录接口
   * @return
   */
  @PostMapping(value = {"/initlogin.json"})
  public ResultModel initlogin(@Valid @RequestBody UserVo userVo) {
    return userService.checkLogin(userVo);
  }

  @PostMapping(value = {"/loginOut.json"})
  public ResultModel loginOut(@RequestBody UserVo userVo) {
    String loginName = userVo.getLoginName();
    return userService.loginOut(loginName);
  }
}
